 <%@ page language="java" import="java.util.*" pageEncoding="utf-8" import="pojo.*,base.*,service.*,java.text.*,java.sql.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


<html>
  <head>
  <link rel="stylesheet" type="text/css" href="jquery/jscal2.css" />
   <link rel="stylesheet" type="text/css" href="jquery/border-radius.css" />
    <link rel="stylesheet" type="text/css" href="jquery/steel/steel.css" />
      <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
    <link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <style type="text/css">

#all a {
           text-decoration:none;
           color:black;
           }

#all a:link,.toptext a:visited{color:black;}
#all a:hover{color:#A020F0;}  


img{border:none;}
body{
	margin:0;
	padding:40px;
	background-image:url("images/bj.jpg");
	background-repeat:no-repeat;
	font:80% Arial, Helvetica, sans-serif;
	color:#555;
	line-height:100%;
}  
#tooltip{
	position:absolute;
	border:1px solid #ccc;
	background:#333;
	padding:2px;
	display:none;
	color:#fff;
}
 #select {
           margin-top:30px
}  
.STYLE1 {font-size: 100%}
</style>
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery/jquery-1.7.2.min.js"></script>
<script >

function openpage(){
 	var page=$("#pagenum").val();
 	location.href="disheslist.jsp?pageno="+page;
 }
 function updateOrderStatus(url){
  if(updateconfirm()){
  location.href=url;
  }
 }
 function updateconfirm(){
	if(confirm("确认要更改订单状态？"))
		return true;
	return false;
 }
 </script>
<script type="text/javascript" src="jquery/jquery-1.6.1.js"></script>
<script type="text/javascript" src="jquery/jquery.validate.min.js"></script>
<script type="text/javascript"></script>
<script src="jquery/jscal2.js"></script>
    <script src="jquery/cn.js"></script>
  </head>
  
  <body>
   <div id="all">
     <div id="list">
<%
	request.setCharacterEncoding("utf-8");
    String spageno = request.getParameter("pageno");
    
    String date = (String)request.getParameter("date");
    String code = (String)request.getParameter("code");
    
    int pageno;//页码
    int pagesize=8;//每页显示行数
    String where=" where 1= 1";           
	if(request.getParameter("status")!=null&&(Integer.parseInt(request.getParameter("status"))!=0)){
   where+=" and tradeStatus="+Integer.parseInt(request.getParameter("status"));
    }
    if(date!=null&&date!=""){
    where+=" and time like'"+date+"%'";
  }
  if(code!=null&&code!=""){
    where+=" and coad ='"+code+"'";
  }
    if(spageno==null){ pageno = 1;}//当页码为空时默认为1
    
    else pageno=Integer.parseInt(request.getParameter("pageno"));//否则为传过来的页码
   OrderService us = new OrderService();
    int size=us.getALL(where);//获取总数量
	try{pageno = Integer.parseInt(spageno);}
	catch(Exception e){}
	
		
	  	

	Page p1=new Page();
								p1.setTotalRecord(size);
								p1.setCurrentPageNo(pageno);
								p1.setPageSize(pagesize);	
	List<order> list = us.getOrder(pageno,pagesize,where);//按参数查询
	SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
	for(int i=0,length=list.size();i<length;i++){
		list.get(i).setDate(df.format(list.get(i).getTime()));
	}
			
			
%>
 
</div>
  <div class="row" style="margin-bottom:20px;">
   <div class="span12">
    <div class="row">
    <div class="span2"> <p class="text-error" style="font-size:15px;">待审核(<a href="orderlist.jsp?status=1"><%=us.countNum(1)%></a>)</p></div>
    <div class="span2"> <p class="text-warning" style="font-size:15px;">等待付款(<a href="orderlist.jsp?status=2"><%=us.countNum(2)%></a>)</p></div>
    <div class="span3"> <p class="text-warning" style="font-size:15px;">今日可完成订单数(<%=us.todayOrder()%>)</p></div>
    <div class="span3"> <p class="text-error" style="font-size:15px;">申请退款订单数(<%=us.countNum(5)%>)</p></div>
    </div>
   </div>
  </div>

	<table class="table table-hover">
      <tr>
        <td width="120"><div align="center">订单时间</div></td>
        <td width="70"><div align="center">订单码号</div></td>
        <td width="50"><div align="center">菜品数量</div></td>
        <td width="100"><div align="center">消费总额</div></td>
        <td width="100"><div align="center">订单状态</div></td>
        <td width="70"><div align="center">操作</div></td>
        
      </tr>
<%
    
	for (order inf : list) {

    out.println("<tr><td><div align='center'>"+inf.getDate()+"</div></td>");
	out.println("<td><div align='center'><a href='orderdetails.jsp?coad="+inf.getCoad()+"'>"+inf.getCoad()+"</a></div></td>");
	out.println("<td><div align='center'>"+inf.getTotalNum()+"</div></td>");
	out.println("<td><div align='center'>"+inf.getTotalPrice()+"</div></td>");
	
	if (inf.getTradeStatus()==1){
	      out.println("<td><div align='center'>等待确认 </div></td>");
	      out.println("<td><div align='center'><input type='button' onclick=updateOrderStatus('action/updateOrderStatus.jsp?id="+inf.getId()+"&orderStatus=2'); value='审核'/></div></td></tr>");
	
	}
	
	else if (inf.getTradeStatus()==2){
	      out.println("<td><div align='center'>已确认等待付款  </div></td>");
	      out.println("<td></td></tr>");
	}
	
	else if (inf.getTradeStatus()==3){
	     if(inf.getPay()==1){
	      out.println("<td><div align='center'>现场付款  </div></td>");
	      out.println("<td><div align='center'><input type='button' onclick=updateOrderStatus('action/updateOrderStatus.jsp?id="+inf.getId()+"&orderStatus=4'); value='完成'/></div></td></tr>");
	}
	else{
	      out.println("<td><div align='center'>已付款   </div></td>");
	      out.println("<td><div align='center'><input type='button' onclick=updateOrderStatus('action/updateOrderStatus.jsp?id="+inf.getId()+"&orderStatus=4'); value='完成'/></div></td></tr>");
	}
	}
	
	else if (inf.getTradeStatus()==4){out.println("<td><div align='center'> 已完成</div></td>");
	      out.println("<td></td></tr>");
	}
	
	else  if (inf.getTradeStatus()==5)
	 {out.println("<td><div align='center'>申请退款 </div></td>");
	      out.println("<td><div align='center'><input type='button' onclick=updateOrderStatus('back.jsp?); value='退款'/></div></td></tr>");
	}
	else if(inf.getTradeStatus()==6){
	{out.println("<td><div align='center'>作废 </div></td>");
	      out.println("<td></td></tr>");
	
	}
	}
	}
	%>
	<%
	
	out.print("<tr><td align='right' colspan='9'><h5>共"+p1.getTotalPage()+"页，当前第"+pageno+"页， ---<a href='orderlist.jsp?&pageno="+p1.getPrePage()+"'>上一页</a>");
								 out.print("<a href='orderlist.jsp?&pageno="+p1.getNextPage()+"'>下一页</a><input type=text name=pagenum id=pagenum style=width:20;border:1px solid grey> <a href='javascript:void(0);' onclick=openpage();>跳转</a></h5></td></tr>");
%>
	
</table>

 
  </div>
	<form  action="orderlist.jsp" method="post">
  <div align="center" id="select">
   订单号 <input type="text" size="20"  id="code" name="code" value=""/>
    日期<input type="text" size="20"  id="date" name="date" value=""/>
    
      <script type="text/javascript">
      Calendar.setup({
        inputField : "date",
        trigger    : "date",
        onSelect   : function() { this.hide() },
        showTime   : 24,
        dateFormat : "%Y-%m-%d"
      });
    </script>
    状态
    <select name="status">
      <option value="0">请选择</option>
      <option value="1">等待确认</option>
      <option value="2">已确认等待付款</option>
      <option value="3">已付款</option>
      <option value="4">已完成</option>
      <option value="5">申请退款</option>
      <option value="6">作废</option>
    </select>
   <input type="submit" value="查询"/>
  </div>
</form>
  </body>
</html>
